// pages/index/house/detail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    huxingtu: [{ title: '3室2厅2卫', imgurl: 'https://pic2.ajkimg.com/display/xinfang/f47da9cbfb15278124d02ccafa07135d/550x500n.jpg', area: '138.00㎡' }, { title: '3室2厅2卫', imgurl: 'https://pic2.ajkimg.com/display/xinfang/f47da9cbfb15278124d02ccafa07135d/550x500n.jpg', area: '138.00㎡' }, { title: '3室2厅2卫', imgurl: 'https://pic2.ajkimg.com/display/xinfang/f47da9cbfb15278124d02ccafa07135d/550x500n.jpg', area: '138.00㎡' }, { title: '3室2厅2卫', imgurl: 'https://pic2.ajkimg.com/display/xinfang/f47da9cbfb15278124d02ccafa07135d/550x500n.jpg', area: '138.00㎡' },],
    map: [{}, { type: '新房', unit: '元/平米', list: [{ title: '区域', value: 'county_name+"-"+site_name' },  { title: '开盘时间', value: 'house_start_time' }, { title: '物管费', value: 'house_wuguan_fee' }, { title: '开发商', value: 'house_company', width: '100' }, { title: '楼盘地址', value: 'house_address', width: 100 }] }, { type: '二手房', unit: '万元', list: [{ title: '区域', value: 'county_name+"-"+site_name' }, { title: '小区', value: 'block_name' }, { title: '房龄', value: 'house_year' }, { title: '楼层', value: 'house_louceng' }] }, { type: '租房', unit: '元/月', list: [{ title: '区域', value: 'county_name+"-"+site_name' }, { title: '小区', value: 'block_name' }, { title: '房龄', value: 'house_year' }, { title: '楼层', value: 'house_louceng' }] }],
    map_info:null,
    fenxiangzhuan: {
      show: false,
      width: '118rpx;',
      height: '100rpx;',
      bottom: '212rpx;',
      top: '16rpx'
    }
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中…',
    })
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    this.setData({
      token: extConfig.appid
    })
    wx.request({
      url: 'https://www.58zltc.com/api.php/House/item/id/' + options.id + '?token=' + this.data.token,
      success: res => {
        this.setData({
          info: res.data,
          map_info: this.data.map[res.data.type]
        })
        wx.setNavigationBarTitle({
          title: res.data.title,
        })
      }
    })

    wx.request({
      url: 'https://www.58zltc.com/api.php/House/zhongjieInfo/id/' + options.id + '?token=' + this.data.token,
      success: res => {
        this.setData({
          zhongjie_info: res.data,
        })
        wx.hideLoading()
      }
    })
  },
  bindCall: function (e) {
    var tel = this.data.info.tel;
    console.log(tel);
    wx.makePhoneCall({
      phoneNumber: tel
    })
  },
  bindCall: function (e) {
    var tel = this.data.info.tel;
    console.log(tel);
    wx.makePhoneCall({
      phoneNumber: tel
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    app.confirmCommission()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this;
    return {
      title: that.data.info.title,
      path: '/pages/index/house/detail?id=' + that.data.info.id + '&fenxiang=' + app.globalData.openid + '&fWid=' + that.data.info.wid,
      success: function (res) {
        var a = that.data.fenxiangzhuan
        a.show = false
        that.setData({
          fenxiangzhuan: a
        })
        // 转发成功
        wx.showToast({
          title: '转发成功！',
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  changeFXZ: function () {
    var that = this;
    var a = that.data.fenxiangzhuan
    a.show ? a.show = false : a.show = true
    that.setData({
      fenxiangzhuan: a
    })
  }
})